﻿; (function (window, undefined, $) {

    $(document).ready(function () {

        var gridopt = {
            //ID, TrustID, Mobilenumber, Reservename
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'ID', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: 'Status', name: 'Status', width: "5%", sortable: true, hide: true, align: 'left' },
                    { display: '资管编号', name: 'AssetID', sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '资管名称', name: 'AssetName', width: "15%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '预约人姓名', name: 'Reservename', width: "5%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '预留电话', name: 'Mobilenumber', width: "15%", sortable: false, hide: false, align: 'left' },
                    { display: '预留时间', name: 'ReserveDate', width: "15%", sortable: false, hide: false, align: 'left' },
                    { display: '操作', name: 'ID', width: "15%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "ReserveDate",
            sortorder: "DESC",
            title: false,
            rp: 10,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            if (cell[1] == 0) {
                ops.push("&nbsp;<a title='受理' href='javascript:;'  onclick=\"util.Accept('", value, "')\"><i class='fa fa-edit' ></i>受理</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[0], "')\"><i class='fa fa-trash-o' ></i>删除</a>");

            } else if (cell[1] == 1) {
                ops.push("&nbsp;&nbsp;已受理");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[0], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            }
            //ops.push("&nbsp;<a title='审核' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>审核</a>");
            //ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
          
            return ops.join("");
        }
        function staOP(value, cell) {
            if (value == 0) {
                return '正常';
            } else if (value == 1) {
                return '不正常';
            }
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            window.location.href = url;
        });
        
        util.See = function (ID) {
            var url = options.ShowUrl + "/" + ID;
            location.href = url;
        };
        util.Edit = function (ID) {
            var url = options.editUrl + "/" + ID;
            location.href = url;
        };
        util.Accept = function (ID) {
            $.post(options.AcceptUrl + "/" + ID, { ID: ID },
       function (res) {
           if (res.Status > 0) {
               alert(res.Message);
               xjgrid.Reload(this);
           }
           else {
               alert(res.Message);
           }
       },
       "json"
 );
        };
        util.Delete = function (ID, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + ID, { ID: ID },
                  function (res) {
                      if (res.Status > 0) {
                          alert(res.Message);
                          xjgrid.Reload(this);
                      }
                      else {
                          alert(res.Message);
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);